package com.yhgarden.bbs.controller.common;

import com.yhgarden.bbs.utils.captcha.CaptchaExtend;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@RequestMapping(value = {"/common/captcha","*/common/captcha"})
public class CaptchaController {

    /**
     * 验证码
     */
    @RequestMapping( value = "", method = RequestMethod.GET )
    public void getCaptcha(HttpServletRequest request,
                           HttpServletResponse response) throws IOException {
        CaptchaExtend.captcha( request, response );
    }

    @RequestMapping( value = "/{width}/{height}", method = RequestMethod.GET )
    public void getCaptcha(@PathVariable int width, @PathVariable int height,
                           HttpServletRequest req, HttpServletResponse response) throws IOException {
        CaptchaExtend.captcha( width, height, req, response );
    }

    @RequestMapping( value = "/{width}/{height}/{count}", method = RequestMethod.GET )
    public void getCaptcha(@PathVariable int width, @PathVariable int height, @PathVariable int count,
                           HttpServletRequest req, HttpServletResponse response) throws IOException {
        CaptchaExtend.captcha( width, height, count, req, response );
    }

}
